function InvDist=MarkovChain_InvDist(CoefMat,FlowVec)

if nargin<=1
    FlowVec     =   [];
end
N   =   length(FlowVec);
if all(FlowVec==0) || isempty(FlowVec)
    [InvDist,EigVal] =   eigs(CoefMat,1,1-1e-6);
    if abs(EigVal-1)>1e-8
        error('Error in Computing the Invariant Distribution');
    end
    if sum(InvDist)<0
        InvDist     =   -InvDist;
    end
    InvDist(InvDist<0)      =   0;
    InvDist     =   InvDist/sum(InvDist);
else
    InvDist     =   (speye(N)-CoefMat)\FlowVec;
    InvDist     =   InvDist/sum(InvDist);
end